/*
 * WindowDelegate.h  0.4.0 / Nov 17, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
#ifndef WINDOWDELEGATE_H
#define WINDOWDELEGATE_H

#include <QList>

#include "Cute4jSwing.h"
#include "ContainerDelegate.h"

// WindowDelegate Class. -------------------------------------------------------

/*!
 * \brief Window Delegate.
 *
 * \author Slobodan Vrkacevic
 * \version 0.4.0
 */
class CUTE4J_EXPORT WindowDelegate : public ContainerDelegate
{
  Q_OBJECT
protected:
  WindowDelegate(JNIEnv *env, jobject obj, QWidget *widget);
  WindowDelegate(JNIEnv *env, jobject obj);
  virtual ~WindowDelegate();
public slots: // native calls
  void setWindowType(JNIEnv *env, jint windowType);
  void setTitle(JNIEnv *env, jstring title);
  void setIconImage(JNIEnv *env, jlong imagePointer);
  void setIconImage(JNIEnv *env, jbyteArray imageData, jint length);
  void setOpacity(JNIEnv *env, jdouble opacity);
  void setAcceptClose(JNIEnv *env, jboolean accept);
  void setModality(JNIEnv *env, jint modality);
  void setState(JNIEnv *env, jint state);
  void setAlwaysOnTop(JNIEnv *env, jboolean alwaysOnTop);
  void setLocationRelativeTo(JNIEnv *env, jlong windowDelegate);
  void toFront(JNIEnv *env);
  void toBack(JNIEnv *env);
  void setBorderDecoration(JNIEnv *env, jint borderDecoration);
public: // native calls
  static void initialize(JNIEnv *env, jclass cls);
  static jboolean opacitySupported(JNIEnv *env, jclass cls);
  static jboolean alwaysOnTopSupported(JNIEnv *env, jclass cls);
  static jboolean fullScreenSupported(JNIEnv *env, jclass cls);
  static jboolean windowShapeSupported(JNIEnv *env, jclass cls);
  static jobjectArray getWindows(JNIEnv *env, jclass cls);
  static jobject getActiveWindow(JNIEnv *env, jclass cls);
  static void setWindowOwner(JNIEnv *env, jclass cls, jlong windowDelegate,
                             jlong ownerDelegate);
  static jlong newInstance(JNIEnv *env, jobject obj);
public: // native callbacks
  void windowOpened();
  void windowClosing();
  void windowClosed();
  void windowActivated();
  void windowDeactivated();
  void windowGainedFocus();
  void windowLostFocus();
  void windowStateChanged(jint oldState, jint newState);
public:
  virtual void showWindow(JNIEnv *env);
protected:
  jint converWindowState(Qt::WindowStates states);
protected:
  virtual bool filterEvent(QObject *obj, QEvent *e);
private:
  bool m_acceptClose;
private:
  static QList<WindowDelegate *> sm_windows;
  static jclass sm_windowClass;
  static jmethodID sm_windowOpenedMID;
  static jmethodID sm_windowClosingMID;
  static jmethodID sm_windowClosedMID;
  static jmethodID sm_windowActivatedMID;
  static jmethodID sm_windowDeactivatedMID;
  static jmethodID sm_windowGainedFocusMID;
  static jmethodID sm_windowLostFocusMID;
  static jmethodID sm_windowStateChangedMID;
};

// Macro Definitions. ----------------------------------------------------------

#define WINDOW_CAST(delegate) (reinterpret_cast<WindowDelegate *>(delegate))
#define WINDOW_DELEGATE WINDOW_CAST(delegate)

#endif // WINDOWDELEGATE_H
